<template>
  <el-container class="home-container">
    <!-- 主体头部内容 -->
    <el-header>
      <div class="header_title">橙翼传媒电商管理系统</div>
      <el-button type="info" @click="loginOut">退出登录</el-button>
    </el-header>
    <el-container>
      <!-- 左侧侧边栏 -->
      <el-aside :width="iscollapse ? '64px':'200px'">
        <div class="aside_collapse" @click="checkCollapse">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409BFF"
          :collapse="iscollapse"
          :collapse-transition="false"
          :default-active="activePath"
          unique-opened
          router
        >
          <!-- 一级 菜单 -->
          <el-submenu :index="item.id + ''" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.authName}}</span>
            </template>

            <!-- 二级 菜单 -->
            <el-menu-item
              :index="'/' + subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
              @click="eleActivePath('/' + subItem.path)"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{subItem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧主体内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      iscollapse: false,
      activePath: '',
      menuList: [
        {
          authName: '代理商管理',
          id: 12,
          path: 'agent',
          children: [
            {
              authName: '添加代理商',
              id: 121,
              path: 'AddAgent'
            },
            {
              authName: '分配屏幕',
              id: 122,
              path: 'Apportion'
            }
          ]
        },
        {
          authName: '屏幕管理',
          id: 13,
          path: 'screen',
          children: [
            {
              authName: '在线状态',
              id: 131,
              path: 'screenStatus'
            },
            {
              authName: '屏幕版本管理',
              id: 132,
              path: 'versions'
            }
          ]
        }
      ]
    }
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    // 点击退出登录
    loginOut() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 切换大小尺寸
    checkCollapse() {
      this.iscollapse = !this.iscollapse
    },
    // 保存点击切换的变量值
    eleActivePath(valPath) {
      window.sessionStorage.setItem('activePath', valPath)
      this.activePath = valPath
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}

.el-header {
  background: #373d41;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-sizing: border-box;
  .header_title {
    color: #fff;
    font-size: 22px;
    font-weight: bold;
  }
  .el-button {
    color: #fff;
    font-size: 14px;
  }
}

.el-aside {
  background: #333744;
  .aside_collapse {
    text-align: center;
    font-size: 10px;
    background: #4a5064;
    color: #fff;
    line-height: 24px;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background: #eaedf1;
}
</style>
